//
//  CZappView.m
//  IOS-9rule
//
//  Created by RIOS on 2018/4/6.
//  Copyright © 2018年 RIOS. All rights reserved.
//

#import "CZappView.h"

@interface CZappView ()
@property (weak, nonatomic) IBOutlet UIButton *btn;


@end

@implementation CZappView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (IBAction)btnClick:(UIButton *)btn {
    NSLog(@"点击了:%ld",(long)btn.tag);
    
    NSInteger width = self.superview.self.frame.size.width;
    
    UILabel *label = [[UILabel alloc] init];
    
    label.text = [NSString stringWithFormat:@"正在下载...%ld",btn.tag];
    label.frame  = CGRectMake(50, 300, width-100, 20);
    [label setTextColor:[UIColor redColor]];
    [label setBackgroundColor:[UIColor grayColor]];
    [label setTextAlignment:NSTextAlignmentCenter];
    [label setFont:[UIFont boldSystemFontOfSize:14]];
    [label.layer setCornerRadius:10];
    [label.layer setMasksToBounds:true];
    [label setAlpha:0];

    
    [UIView animateWithDuration:1 animations:^{
        [label setAlpha:0.8];
    } completion:^(BOOL finished) {
        NSLog(@"finished:%@",finished?@"true":@"false");
        if (finished) {
            [UIView animateWithDuration:0.5 delay:2 options:UIViewAnimationOptionCurveLinear animations:^{
                [label setAlpha:0];
            } completion:^(BOOL finished) {
                if (finished) {
                    [label removeFromSuperview];
                }
                
            }];
        }
        
    }];
    
    [self.superview addSubview:label];
}



+(instancetype)appView{
    CZappView *vView = [[[NSBundle mainBundle] loadNibNamed:@"CZapp" owner:nil options:nil] firstObject];
    return vView;
}

-(void)setModel:(CZapp *)model{
    self.image.image = [UIImage imageNamed:model.icon];
    self.label.text = model.label;
    self.btn.tag = model.positon;
}

@end
